import Taro from '@tarojs/taro'
import { action, observable } from "mobx";
import $http from "../utils/http";


//项目列表
const PROJECT_LIST_URL = 'https://project.weitip.com/index/project/project_lists'
//验收列表
const CHECK_LIST_URL = 'https://project.weitip.com/index/project/project_check_lists'

const TOOL_LIST_URL = 'http://project.weitip.com/index/tool/lists'

export default class ListStore {
  @observable rows: Array<any> = [];
  @observable toolRows: Array<any> = [];

  @action
  clear() {
    this.rows = []
    this.toolRows = []
  }

  @action
  async getDataList(type = 0) {
    let url = PROJECT_LIST_URL
    if (type === 1) url = CHECK_LIST_URL
    Taro.showLoading({ title: '加载中...', mask: true })
    const result = await $http
      .post(url)
      .catch(() => Taro.hideLoading())
    Taro.hideLoading()
    if (result) {
      this.rows = result.rows
    } else {
      Taro.showToast({title: '加载失败请重试', icon: 'none'})
    }
  }

  @action
  async getToolDataList() {
    Taro.showLoading({ title: '加载中...', mask: true })
    const result = await $http
      .post(TOOL_LIST_URL)
      .catch(() => Taro.hideLoading())
    Taro.hideLoading()
    if (result) {
      this.toolRows = result.rows
    } else {
      Taro.showToast({ title: '加载失败请重试', icon: 'none' })
    }
  }
}
